<!-- 客户 -->
<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!-- 用户列表 -->
      <el-col :lg="24" :xs="24">
        <div class="search-container">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
            <el-form-item label="关键字" prop="lawyerName">
              <el-input
                v-model="queryParams.lawyerName"
                placeholder="律师名称"
                clearable
                style="width: 135px !important"
                @keyup.enter="handleQuery"
              />
            </el-form-item>

            <el-form-item>
              <el-button type="primary" @click="handleQuery">
                <i-ep-search />
                搜索
              </el-button>
              <el-button @click="handleResetQuery">
                <i-ep-refresh />
                重置
              </el-button>
            </el-form-item>
          </el-form>
        </div>

        <el-card shadow="never" class="table-container">
          <el-table
            loading="loading"
            :data="pageData"
            @current-change="handleSelectionChange"
            highlight-current-row
            style="width: 100%"
          >
            <el-table-column
              key="lawyerName"
              label="律师名称"
              align="center"
              prop="lawyerName"
            />

            <el-table-column label="律所" align="center" prop="lawFirmName" />
          </el-table>

          <pagination
            v-if="total > 0"
            v-model:total="total"
            v-model:page="queryParams.current"
            v-model:limit="queryParams.pageSize"
            @pagination="handleQuery"
          />
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
defineOptions({
  name: "Customers",
  inheritAttrs: false,
});
import lawyerAPI, { LawyerPageQuery, LawyerPageVO } from "@/api/lawyer";

const emit = defineEmits(["selectLawed"]);

const queryFormRef = ref(ElForm);

const loading = ref(false);
const total = ref(0);
const pageData = ref<LawyerPageVO[]>();

/** 用户查询参数  */
const queryParams = reactive<LawyerPageQuery>({
  cityNo: "",
  lawFirmId: undefined,
  lawyerName: "",
  current: 1,
  pageSize: 10,
});

/**  用户弹窗对象  */
const dialog = reactive({
  visible: false,
  title: "",
});

/** 查询 */
function handleQuery() {
  loading.value = true;
  lawyerAPI
    .getLawyer(queryParams)
    .then((data) => {
      // console.log(data, "律师列表");
      pageData.value = data.records;
      total.value = data.total;
    })
    .finally(() => {
      loading.value = false;
    });
}

/** 重置查询 */
function handleResetQuery() {
  queryFormRef.value.resetFields();
  queryParams.current = 1;
  handleQuery();
}

/** 行单选框选中记录选中ID集合 */
function handleSelectionChange(selection: any) {
  emit("selectLawed", selection);
}

onMounted(() => {
  handleQuery();
});
</script>
<style lang="scss" scoped>
.categoryInfo-item .text::after {
  content: "、";
}
.categoryInfo-item .text:nth-last-of-type(1)::after {
  content: "。";
}
.el-table tbody:focus-visible {
  outline: none;
}
</style>
